# Maintainer: Vincent Torri <vincent.torri@gmail.com>

_realname=lexbor
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.4.0
pkgrel=1
pkgdesc="Fast C99 HTML renderer library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://lexbor.com//'
license=('spdx:Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/lexbor/lexbor/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('8949744d425743828891de6d80327ccb64b5146f71ff6c992644e6234e63930e')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DLEXBOR_BUILD_TESTS=ON \
      -DLEXBOR_BUILD_TESTS_CPP=ON \
      "${extra_config[@]}" \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  # Workaround: try to build twice to fix dll copy issue
  cmake --build "build-${MSYSTEM}" || cmake --build "build-${MSYSTEM}"
}

check() {
  cmake --build "build-${MSYSTEM}" --target test
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
